/*
 * Copyright (c) 2025 Huawei Technologies Co., Ltd.
 * openFuyao is licensed under Mulan PSL v2.
 * You can use this software according to the terms and conditions of the Mulan PSL v2.
 * You may obtain a copy of Mulan PSL v2 at:
 *          http://license.coscl.org.cn/MulanPSL2
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
 * See the Mulan PSL v2 for more details.
 */

// Package k8s create kubernetes config
package k8s

import (
	"reflect"
	"testing"

	"k8s.io/client-go/rest"
)

func TestNewKubernetesCfg(t *testing.T) {
	tests := []struct {
		name string
		want *KubernetesCfg
	}{
		{
			name: "default",
			want: &KubernetesCfg{
				KubeConfigFile: getKubeConfigFile(),
				KubeConfig:     GetKubeConfig(),
				QPS:            1e6,
				Burst:          1e6,
			},
		},
	}
	for _, tt := range tests {
		t.Run(tt.name, func(t *testing.T) {
			if got := NewKubernetesCfg(); !reflect.DeepEqual(got, tt.want) {
				t.Errorf("NewKubernetesCfg() = %v, want %v", got, tt.want)
			}
		})
	}
}

func TestGetKubeConfigFile(t *testing.T) {
	tests := []struct {
		name string
		want string
	}{
		{
			name: "default",
			want: "",
		},
	}
	for _, tt := range tests {
		t.Run(tt.name, func(t *testing.T) {
			if got := getKubeConfigFile(); got != tt.want {
				t.Errorf("getKubeConfigFile() = %v, want %v", got, tt.want)
			}
		})
	}
}

func TestKubernetesCfgValidate(t *testing.T) {
	type fields struct {
		KubeConfigFile string
		KubeConfig     *rest.Config
		QPS            float32
		Burst          int
	}
	tests := []struct {
		name   string
		fields fields
		want   []error
	}{
		{
			name: "valid config",
			fields: fields{
				KubeConfigFile: getKubeConfigFile(),
				KubeConfig:     GetKubeConfig(),
				QPS:            1e6,
				Burst:          1e6,
			},
			want: []error{},
		},
	}
	for _, tt := range tests {
		t.Run(tt.name, func(t *testing.T) {
			k := &KubernetesCfg{
				KubeConfigFile: tt.fields.KubeConfigFile,
				KubeConfig:     tt.fields.KubeConfig,
				QPS:            tt.fields.QPS,
				Burst:          tt.fields.Burst,
			}
			if got := k.Validate(); len(got) != len(tt.want) {
				t.Errorf("KubernetesCfg.Validate() = %v, want %v", got, tt.want)
			}
		})
	}
}
